package cn.edu.ncut.cs.springboot.mybatisplusemployee.controller;

import cn.edu.ncut.cs.springboot.mybatisplusemployee.entity.Employees;
import cn.edu.ncut.cs.springboot.mybatisplusemployee.service.IEmployeesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ncut
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/employees")
public class EmployeesController {
    @Autowired
    private IEmployeesService employeesService;

    @PutMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody Employees employee) {
        return employeesService.saveOrUpdate(employee);
    }

    @GetMapping("/list")
    public List<Employees> list() {
        return employeesService.list();
    }

    @DeleteMapping("/delete/{number}")
    public boolean deleteEmployee(@PathVariable Integer number) {
        return employeesService.removeEmployeeByNumber(number);
    }

    @GetMapping("/{number}")
    public Employees getEmployeeByNumber(@PathVariable Integer number) {
        return employeesService.getEmployeeByNumber(number);
    }
}
